using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CordRear : MonoBehaviour
{
    public bool isConnected;
    public string rearName;
    public float length;

    public void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.CompareTag("Player"))
        {
            Character player = collision.GetComponent<Character>();
            if(!player.cordRears.Contains(this))
            {
                player.cordRears.Add(this);
            }
        }
    }

    public void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            Character player = collision.GetComponent<Character>();
            if(player.cordRears.Count != 0)
            {
                for(int i = 0; i < player.cordRears.Count; i++)
                {
                    if(player.cordRears[i].rearName == rearName)
                    {
                        player.cordRears.Remove(player.cordRears[i]);
                    }
                }
            }
        }
    }
}
